package controller

import (
	"github.com/labstack/echo"
	"model"
)

type UserController struct{}

func (UserController) Login(ctx echo.Context) error {
	req := new(LoginReq)
	// 参数绑定
	err := ctx.Bind(req)
	if err != nil {
		ctx.Error(err)
		return ctx.JSON(200, map[string]interface{}{
			"err": err,
		})
	}

	// 查询数据库
	has,user:=model.Login(req.Username)
	if !has {
		return ctx.JSON(200, map[string]interface{}{
			"err": "用户不存在" + req.Username,
		})
	}
	return ctx.JSON(200, map[string]string{
		"status": "success:" + user.Password,
	})
}
